<template>
  <el-table :data="tableData6" border show-summary style="width: 100%" :span-method="objectSpanMethod">
    <el-table-column prop="id" label="楼盘" width="180"></el-table-column>
    <el-table-column prop="name" label="收房日期" width="300"></el-table-column>
    <el-table-column prop="amount3" sortable label="订单数"></el-table-column>
  </el-table>
</template>
<script>
export default {
    data() {
      return {
        tableData6: [{
          id: '复地上城',
          name: '2019-02-28',
          amount3: 10
        }, {
          id: '复地上城',
          name: '2019-02-28',
          amount3: 12
        }, {
          id: '复地上城',
          name: '2019-02-28',
          amount3: 9
        }, {
          id: '复地上城',
          name: '2019-02-28',
          amount3: 17
        }, {
          id: '复地上城',
          name: '未知',
          amount3: 15
        }]
      };
    },
    methods: {
      getSummaries(param) {
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index] += ' 元';
          } else {
            sums[index] = 'N/A';
          }
        });

        return sums;
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex === 0) {
          if (rowIndex % 5 === 0) {
            return {
              rowspan: 5,
              colspan: 1
            };
          } else {
            return {
              rowspan: 0,
              colspan: 0
            };
          }
        }
      }
    }
  };
</script>
<style lang="less" scoped>
</style>
